<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// ------------------------------------------------------------------------

/**
 * CodeIgniter Media Helpers
 *
 * Manage media file for codeigiter template.
 *
 * @package		CodeIgniter
 * @subpackage	Helpers
 * @category	Helpers
 * @author		Sikarin Engkased
 */

// --------------------------------------------------------------------

/**
 * js_datepicker
 *
 * return media file for datepicker
 *
 * @access	public
 * @param	string
 * @return	str
 */	
if ( ! function_exists('js_datepicker'))
{	
	function js_datepicker($selector=".datepicker")
	{		
		$js = '<link rel="stylesheet" href="media/js/date_input/date_input.css" type="text/css" media="screen" />';
		$js .= '<script type="text/javascript" src="media/js/date_input/jquery.date_input.js"></script>';
		$js .= '<script type="text/javascript">
					$(function(){
		    		jQuery.extend(DateInput.DEFAULT_OPTS, {
	  					month_names: ["มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม"],
	  					short_month_names: ["ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค."],
	 					short_day_names: ["อ.","จ.", "อ.", "พ.", "พฤ.", "ศ.", "ส."],
	  						stringToDate: function(string) {
	   							var matches;
	    						if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) 
								{
	      							return new Date(matches[1], matches[2] - 1, matches[3]);
	    						} 
								else 
								{
	      							return null;
	    						};
	 						},
							dateToString: function(date) {
	    						var month = (date.getMonth() + 1).toString();
	    						var dom = date.getDate().toString();
	    						if (month.length == 1) month = "0" + month;
	    						if (dom.length == 1) dom = "0" + dom;
	    						return date.getFullYear() + "-" + month + "-" + dom;
	  						}
	
						});
						$("input.datepicker").date_input(); 
					});
				</script>';
		return $js; 
	}
}

// --------------------------------------------------------------------

/**
 * set_notify
 *
 * set notify Bar
 *
 * @access	public
 * @param	string
 * @param	string
 * @return	str
 */	
if(!function_exists('set_notify'))
{
	function set_notify($type,$msg)
	{
		$config = array(
			'notify' => TRUE,
			'type' => $type,
			'msg' => $msg
		);
		$CI =& get_instance();
		$CI->session->set_flashdata($config);
	}
}

// --------------------------------------------------------------------

/**
 * js_notify
 *
 * Display notify Bar
 *
 * @access	public
 * @return	str
 */	
if(!function_exists('js_notify'))
{
	function js_notify()
	{
		$CI =& get_instance();
		if($CI->session->flashdata('notify'))
		{
			$js = '<link rel="stylesheet" href="media/js/jquery.jnotify/css/jquery.jnotify-alt.css" type="text/css" media="screen" />';
		    $js .= '<script type="text/javascript" src="media/js/jquery.jnotify/js/jquery.jnotify.min.js"></script>';
		    $js .= '<script type="text/javascript">
		    				$(function () {
								$.jnotify("'.$CI->session->flashdata('msg').'",{
									type: "'.$CI->session->flashdata('type').'",
									delay: 2000,
								});
							});
						</script>';
			return $js; 
		}
	}
}

// --------------------------------------------------------------------

/**
 * js_lightbox
 *
 * Display Lightbox
 *
 * @access	public
 * @return	str
 */	
if(!function_exists('js_lightbox'))
{
	function js_lightbox()
	{
		$js = '<link rel="stylesheet" href="media/js/prettyPhoto/prettyPhoto.css" type="text/css" media="screen" />';
		$js .= '<script type="text/javascript" src="media/js/prettyPhoto/jquery.prettyPhoto.js"></script>';
		    $js .= '<script type="text/javascript">
		    				$(function () {
						  		$("a[rel^=lightbox]").prettyPhoto({theme:\'facebook\'});
							});
						</script>';
			return $js; 
		
	}
}

if(!function_exists('js_checkbox'))
{
	function js_checkbox()
	{
		return '<script type="text/javascript" src="media/js/checkbox/js/iphone-style-checkboxes.js"></script>
		<link rel="stylesheet" href="media/js/checkbox/style.css" type="text/css" media="screen" />
		<script type="text/javascript">
		$(":checkbox").iphoneStyle();
		</script>';
	}
}

// --------------------------------------------------------------------

/**
 * js_form_helper
 *
 * Display Javascript from FormHelper
 *
 * @access	public
 * @return	str
 */	
if(!function_exists('js_form_helper'))
{
	function js_form_helper()
	{
		$CI =& get_instance();
		if($CI->session->flashdata('tinymce'))
		{
			$CI->template->append_metadata('<script type="text/javascript" src="media/tiny_mce/tiny_mce.js"></script>');
			$CI->template->append_metadata('<script type="text/javascript" src="media/js/tinymce.js"></script>');
		}
		if($CI->session->flashdata('datepicker'))
		{
			$CI->template->append_metadata(js_datepicker());
		}
	}
}

// --------------------------------------------------------------------

/* End of file media_helper.php */
/* Location: ./application/helpers/media_helper.php */